// pages/link/link.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    istrue:false,
    index:2,
    list:[],
    opentrue:false,
    avindex:0,
    qrcodetrue:false, //开启关闭二维码
    qrcode:'iVBORw0KGgoAAAANSUhEUgAAAIQAAACEAQMAAABrihHkAAAABlBMVEX///8AAABVwtN+AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAyUlEQVRIie2UwQ3DMAwDtQH331IbqCSdFM2nRcw+IxiGdQ+DoiVXPfEjZqZRAx8C0lpD4kNAprXgPSQYzD8IpSEmXKBxfan9PpHhjstb3Cemb3X7hBlX0bJD4Cah7+wmk7P2LaKnA433GwSEOQHcEBWQUjdxk9JOCDPYL1RCeNTEqc5JCKeEykZCj0r3SK8EbMxKyEklswOiAVHa+k0C0qsZZFtFZA2u9CEl9Ev3nhO3Tfyb4FPhBim3FDx4AfGtMn+N7zZ54ku8AGxKJ5rKth5zAAAAAElFTkSuQmCC',
    id:null,
  },
  getlist(e){
    let that = this; 
    var prolist = wx.getStorageSync('prolist')
    wx.request({
      url: 'https://wxtp.hephp.cn/Api/Group/getlist', //仅为示例，并非真实的接口地址
      data: {
        uid:prolist.data.uid,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        let prolist = res.data.data;
        prolist[0].flag=true
        console.log(prolist)
        that.setData({
          list:prolist
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this; 
    that.getlist()
  },
  onopen(e){
    let that = this;
    let flag = e.currentTarget.dataset.flag;
    let item = e.currentTarget.dataset.item;
       // 数据
       let data = that.data.list;
       data.forEach((outItem) => {
         if (outItem.id === item.id) {
           if(flag==true){
             outItem.flag = false;
           }else{
             //将点击的数据变成true
             outItem.flag = true;
         } 
   
         } else {
           // 如果当前点击和其他的不同，其他的都变成false
           outItem.flag = false;
         }
       })
   
       // 数据变化
       this.setData({
        list: data,
       })
  },
  // 添加链接
  onaddlinks(e){
    wx.navigateTo({
      url: '/pages/putong/putong',
    })
  },


  // 复制链接
  oncopy(e){
    let code = e.currentTarget.dataset.code
    console.log(code)
    wx.setClipboardData({
      data: code, //获取wxml页面中data-key的值
      success: function (res) {
      wx.showModal({
      title: '提示',
      content: '复制成功',
      success: function (res) {
      if (res.confirm) {
      console.log('确定')
      } else if (res.cancel) {
      console.log('取消')
      }
      }
      })
      }
      })
  },
  //生成二维码
  oncode(e){
    let code = e.currentTarget.dataset.code
    console.log(code)
    let that = this;
    that.setData({
      qrcodetrue:true,
      qrcode:code
    })
  },
  //信息内容
  oninfo(e){
    let id = e.currentTarget.dataset.id
   // console.log(e)
    let that = this;
    that.setData({
      id:id,
      opentrue:true
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this
    that.getlist()
  },

})